define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	//查询学年学期
	httpService.post(app.urls.prop_select,{"prop_group":'SCORE',"prop_key":'STU_YEAR'},function(data){
		if("0000" === data.code){
			$scope.academics =  data.data;
		}else{
			alert(data.msg);
		}
	});
	//查询学期
	httpService.post(app.urls.prop_select,{"prop_group":'SCORE',"prop_key":'STU_TERM'},function(data){
		if("0000" === data.code){
			$scope.semesters = data.data;
		}else{
			alert(data.msg);
		}
	});
	//查询主校区和分校区
	httpService.post(app.urls.unit_selectSchoolAndAttach,{},function(data){
		if("0000" === data.code){
			$scope.unitList = data.data;
		}else{
			alert(data.msg);
		}
	});
	//查询年级
	$scope.findGrade = function (){
		httpService.post(app.urls.grade_selectCenterGrade,$scope.form,function(data){
			if("0000" === data.code){
				$scope.gradeList = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	//获取班级
	$scope.findClass=function(){
		httpService.post(app.urls.class_selectClassName,$scope.form,function(data){
			if("0000" === data.code){
				$scope.classList = data.data;
				$scope.findCourse();
			}else{
				alert(data.msg);
			}
		});
	}
	//查询课程
	$scope.findCourse=function(){
		httpService.post(app.urls.course_selectByflag,$scope.form, function (data) {
			if ("0000" === data.code) {
				$scope.courseList = data.data;
			} else {
				alert(data.msg);
			}
		});
	}
	var init =function(){
		//查询当前学年学期
		httpService.post(app.urls.prop_select,{"prop_group":'SCORE','status':'0'},function(data){
			if("0000" === data.code){
				for(var i=0;i<data.data.length;i++){
					if(data.data[i].prop_key=='STU_YEAR'){
						$scope.form.academic =  data.data[i].prop_pk;
					}
					if(data.data[i].prop_key=='STU_TERM'){
						$scope.form.semester =  data.data[i].prop_pk;
					}
				}
				$scope.find();
			}else{
				alert(data.msg);
			}
		});
	}
	init();
	//查询教师数据
	$scope.find = function(){
		httpService.postpage(app.urls.teacher_selectToList,$scope.form,function(data){
			if("0000" === data.code){
				$scope.rows = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	$scope.find();
	//按钮点击事件-条件查询
	$scope.select = function(){
    	$scope.page.current = 1;
    	$scope.find();
    }
	$scope.saveForm = function(){
		var values = [];
		$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){ 
			values.push($(this).val());
		});
		if($scope.formCheck()){
			if(values.length < 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择添加数据。"});
			}else if(values.length > 1){
				eventBusService.publish('modal.alert', {"title":"操作提示","content":"您选择了多行数据，请重新选择。"});
			}else{
				httpService.post(app.urls.course_info_selectIfExit,$scope.form,function(data){
					if(data.data==0){
						$scope.form.fk_user = values[0];
						httpService.post(app.urls.course_info_insert,$scope.form,function(data){
							if("0000" === data.code){
								eventBusService.publish("content.page.reload",data.data);
								eventBusService.publish("modal.page.close",{});
							}else{
								alert(data.msg);
							}
						});
					}else{
						alert("已经添加过该课程信息，无需重复添加");
					}
				});
			}
		}
	}
	
}}});